import { COLOR, formarColor, CreatePosition } from '../Config'
import { ElementEntity } from './ElementEntity';
import Label from './Label';

class IconEntity extends ElementEntity {
    constructor(options = {}) {
        super(options.id, options, options.onClick, options.onRightClick);
        this.EntityTypeName = 'ElementEntity'
        this.Entity.position = CreatePosition(options.point);
        var _image = options.image || {};
        this.Entity.billboard = new Cesium.BillboardGraphics({
            // 图标地址
            image: _image.url,
            // 宽度
            width: (_image.size && _image.size.width) || 32,
            // 高度
            height: (_image.size && _image.size.height) || 32,
            // 旋转
            rotation: _image.rotation || 0,
            // 颜色
            color: formarColor(_image.color),
            // 按照像素显示 或者按照米显示
            sizeInMeters: _image.sizeInMeters || false,
            // 像素偏移量
            pixelOffset: new Cesium.Cartesian2((_image.Offset && _image.Offset[0]) || 0, (_image.Offset && _image.Offset[1]) || 0),
            // 世界空间中的对齐轴
            alignedAxis: Cesium.Cartesian3.ZERO,
            // 水平对齐方式
            horizontalOrigin: Cesium.HorizontalOrigin[_image.horizontal || 'CENTER'],
            // 垂直对齐方式
            verticalOrigin: Cesium.VerticalOrigin[_image.vertical || 'CENTER'],
            // 贴地
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
        })
        this.label = new Label(this.Entity, options.label, {});
    }
    set point(position) {
        this.Entity.position = CreatePosition(position);
    }
    get point() {
        return this.Entity.position;
    }

    set show(show) {
        this.Entity.show = !!show
    }
    get show() {
        return this.Entity.show;
    }
    set url(url) {
        this.Entity.billboard.image = url
    }
    get url() {
        return this.Entity.billboard.image;
    }
    set color(color) {
        this.Entity.billboard.color = formarColor(color)
    }
    get color() {
        return this.Entity.billboard.color;
    }
    set rotation(rotation) {
        this.Entity.billboard.rotation = rotation || 0;
    }
    get rotation() {
        return this.Entity.billboard.rotation;
    }
    set offset(offset) {
        this.Entity.billboard.pixelOffset = new Cartesian2(offset[0] || 0, offset[1] || 0);
    }
    get offset() {
        return this.Entity.billboard.pixelOffset;
    }
    set sizeInMeters(sizeInMeters) {
        this.Entity.billboard.sizeInMeters = !!sizeInMeters
    }
    get sizeInMeters() {
        return this.Entity.billboard.sizeInMeters;
    }
    set horizontal(horizontal) {
        this.Entity.billboard.horizontalOrigin = Cesium.HorizontalOrigin[horizontal || 'CENTER']
    }
    get horizontal() {
        return this.Entity.billboard.horizontalOrigin;
    }
    set vertical(vertical) {
        this.Entity.billboard.verticalOrigin = Cesium.verticalOrigin[vertical || 'CENTER']
    }
    get vertical() {
        return this.Entity.billboard.verticalOrigin;
    }
}


export default IconEntity;